<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="java.io.File"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.io.BufferedInputStream"%>
<%@page import="java.io.BufferedOutputStream"%>
<%@page import="java.io.OutputStream"%>
<%@page import="com.ks.app.admin.util.BeanFactory"%>
<%@page import="com.ks.app.admin.service.KsVersionService"%>
<%@page import="java.net.URLEncoder"%>
<%
java.io.BufferedOutputStream  bos=null;
try
{
	//String fileName = "1.zip";
	String isdown=request.getParameter("isdown")==null?"0":request.getParameter("isdown").toString().trim();
	String src=request.getParameter("src")==null?"320X480":request.getParameter("src").toString().trim();
	String loc_ver=request.getParameter("ver")==null?"0":request.getParameter("ver").toString().trim();
	String clnt=request.getParameter("clnt")==null?"":request.getParameter("clnt").toString().trim();;
	String smsc=request.getParameter("smsc")==null?"0100":request.getParameter("smsc").toString().trim();
	String imsi=request.getParameter("imsi")==null?"0":request.getParameter("imsi").toString().trim();
	
	String str=request.getQueryString();
	String path0=getServletContext().getRealPath("/");
	KsVersionService ks = (KsVersionService) BeanFactory.getBean("ksVersionService");
	String path=ks.getApkfilepath(loc_ver,isdown).trim();    	
    if(path.length()>0)
    { 
   		 String fname=path.substring(path.lastIndexOf("\\")+1);
    	 File file=new File(path); 
	     if(file.exists())
	     {
	     	   fname=URLEncoder.encode(fname,"utf-8");
			   InputStream  ins=new FileInputStream(path); 
	     	   BufferedInputStream bins=new BufferedInputStream(ins);//放到缓冲流里面 
	           OutputStream outs=response.getOutputStream();//获取文件输出IO流 
	           BufferedOutputStream bouts=new BufferedOutputStream(outs); 
	           response.setContentType("application/x-download");//设置response内容的类型 
	           response.setHeader("Content-disposition","attachment;filename="+ fname);//设置头部信息 
	           int bytesRead = 0; 
	           byte[] buffer = new byte[8192]; 
	           //开始向网络传输文件流 
	           while ((bytesRead = bins.read(buffer, 0, 8192)) != -1) { 
	               bouts.write(buffer, 0, bytesRead); 
	           } 
	           bouts.flush();//这里一定要调用flush()方法 
	           ins.close(); 
	           bins.close(); 
	           outs.close(); 
	           bouts.close(); 			
		}
	}
}
catch( Exception e )
{
    out.write("error:" + e);
}

finally {
	out.clear();
		out = pageContext.pushBody();
    if (bos != null)bos.close();
}
%>